home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / tcisam.zip / IREADN.C < prev    next >
Text File  |  1987-08-21  |  2KB  |  52 lines

  1. /*
  2.  * IREADN.C - read next
  3.  *
  4.  *                      Copyright (c) 1987, Jim Mischel
  5.  * Modifications:
  6.  *
  7.  * 08/13/87 - jim - original coding
  8.  */
  9.  
  10. #include "inxdefs.h"
  11.  
  12. /*
  13.  * iread_next() - return the next record in sequence.  The file must be
  14.  * started using istart() before this routine is called.  If successful
  15.  * returns 0 with data record at destin.  At end of file, EOF is returned.
  16.  * Any other errors return status.  In the case of EOF or error, the data at
  17.  * destin is unchanged.
  18.  *
  19.  * This routine assumes there is enough space at 'dest' to store the entire
  20.  * data record.
  21.  */
  22. int iread_next(void *d, void *dest)
  23. {
  24.   df_rec *db_control = (df_rec *)d;
  25.   char *destin = (char *)dest;
  26.  
  27.   if (db_control->df_flags & DF_EOF)
  28.     return(EOF);                        /* already reached end of file */
  29.   /*
  30.    * if this is not the first read after starting the file, get the
  31.    * next index record into the buffer.
  32.    */
  33.   if (!(db_control->df_flags & DF_START)) {
  34.     if (iget_next(db_control,&db_control->df_nxt_buff))
  35.       return(EOF);
  36.     memcpy(&db_control->df_nxt_buff,&db_control->df_inx_buff,sizeof(inx_rec));
  37.   }
  38.   else
  39.     db_control->df_flags &= ~DF_START;  /* reset first read flag */
  40.  
  41.   /* get the data record */
  42.   if (iread_dat(db_control,db_control->df_nxt_buff.if_dat_ptr))
  43.     return(ierrno);
  44.  
  45.   db_control->df_flags &= ~DF_TOF;      /* clear top-of-file flag */
  46.   db_control->df_flags &= ~DF_DELETE;   /* clear deleted record flag */
  47.  
  48.   /* copy the data record from data buffer into user's area */
  49.   memcpy(destin,db_control->df_dat_buff,db_control->df_rec_size);
  50.   return(0);
  51. } /* iread_next */
  52.